﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TSVNAddin.Core
{
	public class SetWorkingRootCommand : ICommand
	{
		WorkingRootRecover _WorkingRootDialogAdapter;
		WorkingContext _WorkingContext;

		public SetWorkingRootCommand(WorkingRootRecover workingRootDialogAdapter, WorkingContext workingContext)
		{
			_WorkingRootDialogAdapter = workingRootDialogAdapter;
			_WorkingContext = workingContext;
		}

		public void Execute()
		{
			string currentWorkingRoot = _WorkingContext.GetWorkingRoot();
			string newWorkingRoot = _WorkingRootDialogAdapter.ChooseWorkingRoot(currentWorkingRoot);
			_WorkingContext.SetWorkingRoot(newWorkingRoot);
		}

		public CommandStatus QueryStatus()
		{
			if (!_WorkingContext.CanSetWorkingRoot())
				return CommandStatus.Disabled;

			return CommandStatus.Enabled;
		}
	}
}
